#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
    //close(0);
    //close(1);
    umask(0);
    //int fd = open("log.txt",O_WRONLY | O_CREAT | O_TRUNC, 0666);
    //int fd = open("log.txt",O_WRONLY | O_CREAT | O_APPEND, 0666);
    int fd = open("log.txt",O_RDONLY);
    if( fd < 0 )
    {
        perror("open");
        return 1;
    }
   dup2(fd, 0); 
   char line[64];

   while(1)
   {
       printf("> ");
       if(fgets(line, sizeof(line), stdin) == NULL)
       {
           break;
       }
       printf("%s",line);
   }

   // dup2(fd,1);
   // printf("open fd : %d\n",fd);
   // fprintf(stdout,"open fd : %d\n",fd);
    
    const char *msg = "hello world";
    write(1, msg, strlen(msg));
    fflush(stdout);
    return 0;
}

